package com.wxtf.platform.main.contraceptives;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import com.wxtf.platform.interfaces.CommonsCallProvider;
import com.wxtf.platform.plugins.user.UserBean;
import com.wxtf.platform.supers.LogicBase;
import com.wxtf.platform.tools.AccessDataBaseUtil;
import com.wxtf.platform.tools.Common;
import com.wxtf.platform.tools.ConstantInfoHelper;
import com.wxtf.platform.tools.FormatUtil;
/**
 * <li>Title: TmaIncomePlanMainAction.java</li>
 * <li>Project: baseplatform</li>
 * <li>Package: com.wxtf.platform.main.contraceptives</li>
 * <li>Description: 药具入库计划主表</li>
 * <li>Copyright: Copyright (c) 2012</li>
 * <li>Company: wxthtf Technologies </li>
 * <li>Created on Jul 5, 2012 10:08:48 AM</li>
 *
 * @author liu_zhaojun
 * @version 1.0.0.0
 *
 */
public class TmaIncomePlanMainAction extends LogicBase implements CommonsCallProvider {
	
	private static Log log = LogFactory.getLog(TmaIncomePlanMainAction.class);

	public TmaIncomePlanMainAction(String jsonArray) {

	}
	
	/** 
	 * 描述：delete 删除入库计划记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	@Override
	public Object delete(Object jsonArray) throws Exception {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		String id = jsonObject.getString("ids");
		String[] ids = id.split(",");
		String sql = "delete from tma_income_plan_main where tmaipm_id = ?";
		AccessDataBaseUtil.deleteByIds(sql, ids);
		return "\"删除成功\"";
	}
	
	/**
	 * 编号
	 * @param sql 要查询的sql
	 * @return
	 * @throws Exception 
	 */
	public String getCode(String sql) throws Exception{
		String code = "";
		String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		String bianhao = "00001";
		boolean bool = true;
		while(bool){
			code = time + bianhao;
			int Id = AccessDataBaseUtil.queryForInt(sql,new Object[]{code});
			if(Id==0){
				break;
			}
			int i = Integer.valueOf(bianhao);
			i++;
			String s = "";
			int a = bianhao.length();
			int b = Integer.toString(i).length();
			while(a - b > 0){
				s += "0";
				a--;
			}
			bianhao = s + i;
		}
		return code;
	}
	/** 
	 * 描述：insert 增加入库计划记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	@Override
	public Object insert(Object jsonArray) throws Exception {		
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		UserBean user = (UserBean)(this.getRequest()).getSession().getAttribute("userBean");
		String org_id = user.getCurOrgId();
		String tmaipm_code = getCode("select count(*) from tma_income_plan_main where tmaipm_code=?");
		String create_time = FormatUtil.getCurentDate();				
		String tmaipm_id = AccessDataBaseUtil.getPKUUID();
		String create_by = user.getUserId();
		String tmaipm_is_valid = jsonObject.getString("tmaipm_is_valid");
		List<String> list = new ArrayList<String>();
		StringBuffer buff = new StringBuffer("insert into tma_income_plan_main(tmaipm_id,org_id,tmaipm_type,tmaipm_is_valid,tmaipm_code,tmaipm_time,tmaipm_year,create_by,create_time,last_modify_by,last_modify_time) values(");
		buff.append("'").append(tmaipm_id).append("'")
		.append(",'").append(org_id).append("'")
		.append(",'").append(jsonObject.getString("tmaipm_type")).append("'")
		.append(",'").append(tmaipm_is_valid).append("'")
		.append(",'").append(tmaipm_code).append("'")
		.append(",'").append(jsonObject.getString("tmaipm_time")).append("'")
		.append(",'").append(jsonObject.getString("tmaipm_year")).append("'")
		.append(",'").append(create_by).append("'")
		.append(",'").append(create_time).append("'")
		.append(",'").append(create_by).append("'")
		.append(",'").append(create_time).append("')");
		list.add(buff.toString());
		buff.setLength(0);
		String ids = jsonObject.getString("ids");
		array = JSONArray.fromObject(ids);
		for(int i=0;i<array.size();i++){
			jsonObject = array.getJSONObject(i);
			buff.append("insert into tma_income_plan_detail(tmaipd_id,tmaipm_id,tmad_id,tmaipm_num,tmaipm_packages_num,create_by,create_time,last_modify_by,last_modify_time) values(")
			.append("'").append(AccessDataBaseUtil.getPKUUID()).append("'")
			.append(",'").append(tmaipm_id).append("'")
			.append(",'").append(jsonObject.getString("tmad_id")).append("'")
			.append(",'").append(jsonObject.getString("tmaid_num")).append("'")
			.append(",'").append(jsonObject.getString("tmaipm_packages_num")).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("')");
			list.add(buff.toString());
			buff.setLength(0);
		}
		if("1".equals(tmaipm_is_valid)){
			String tmaim_code = getCode("select count(*) from TMA_INCOME_MAIN where tmaim_code=?");
			String tmaim_id = AccessDataBaseUtil.getPKUUID();
			buff = new StringBuffer("insert into TMA_INCOME_MAIN(tmaim_id,org_id,tmaim_type,tmaim_is_valid,tmaim_code,tmaim_time,create_by,create_time,last_modify_by,last_modify_time) values(");
			buff.append("'").append(tmaim_id).append("'")
			.append(",'").append("1").append("'")
			.append(",'").append("0").append("'")
			.append(",'").append("1").append("'")
			.append(",'").append(tmaim_code).append("'")
			.append(",'").append(create_time).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("')");
			list.add(buff.toString());
			buff.setLength(0);
			array = JSONArray.fromObject(ids);
			for(int i=0;i<array.size();i++){
				jsonObject = array.getJSONObject(i);
				buff.append("insert into TMA_INCOME_DETAIL(tmaid_id,tmaim_id,tmad_id,tmaid_num,create_by,create_time,last_modify_by,last_modify_time) values(")
				.append("'").append(AccessDataBaseUtil.getPKUUID()).append("'")
				.append(",'").append(tmaim_id).append("'")
				.append(",'").append(jsonObject.getString("tmad_id")).append("'")
				.append(",'").append(jsonObject.getString("tmaid_num")).append("'")
				.append(",'").append(create_by).append("'")
				.append(",'").append(create_time).append("'")
				.append(",'").append(create_by).append("'")
				.append(",'").append(create_time).append("')");
				list.add(buff.toString());
				buff.setLength(0);
			}
		}
		AccessDataBaseUtil.executeSQLUpdate(list);
		return "\"新建成功\"";
	}
	/** 
	 * 描述：update 修改入库计划记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	@Override
	public Object update(Object jsonArray) throws Exception {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		UserBean user = (UserBean)(this.getRequest()).getSession().getAttribute("userBean");
		String org_id = user.getCurOrgId();
		String create_time = FormatUtil.getCurentDate();				
		String tmaipm_id = jsonObject.getString("tmaipm_id");
		String create_by = user.getUserId();
		String tmaipm_is_valid = jsonObject.getString("tmaipm_is_valid");
		List<String> list = new ArrayList<String>();
		StringBuffer buff = new StringBuffer("update tma_income_plan_main set ");
		buff.append("org_id='").append(org_id).append("'")
		.append(",tmaipm_type='").append(jsonObject.getString("tmaipm_type")).append("'")
		.append(",tmaipm_is_valid='").append(tmaipm_is_valid).append("'")
		.append(",tmaipm_code='").append(jsonObject.getString("tmaipm_code")).append("'")
		.append(",tmaipm_time='").append(jsonObject.getString("tmaipm_time")).append("'")
		.append(",tmaipm_year='").append(jsonObject.getString("tmaipm_year")).append("'")
		.append(",last_modify_by='").append(create_by).append("'")
		.append(",last_modify_time='").append(create_time).append("'")
		.append(" where tmaipm_id='").append(tmaipm_id).append("'");
		list.add(buff.toString());
		buff.setLength(0);
		String ids = jsonObject.getString("ids");
		array = JSONArray.fromObject(ids);
		for(int i=0;i<array.size();i++){
			jsonObject = array.getJSONObject(i);
			buff.append("update tma_income_plan_detail set ")
			.append("tmaipm_id='").append(tmaipm_id).append("'")
			.append(",tmad_id='").append(jsonObject.getString("tmad_id")).append("'")
			.append(",tmaipm_num='").append(jsonObject.getString("tmaid_num")).append("'")
			.append(",tmaipm_packages_num='").append(jsonObject.getString("tmaipm_packages_num")).append("'")
			.append(",last_modify_by='").append(create_by).append("'")
			.append(",last_modify_time='").append(create_time).append("'")
			.append(" where tmaipd_id='").append(jsonObject.getString("tmaipd_id")).append("'");
			list.add(buff.toString());
			buff.setLength(0);
		}
		if("1".equals(tmaipm_is_valid)){
			String tmaim_code = getCode("select count(*) from TMA_INCOME_MAIN where tmaim_code=?");
			String tmaim_id = AccessDataBaseUtil.getPKUUID();
			buff = new StringBuffer("insert into TMA_INCOME_MAIN(tmaim_id,org_id,tmaim_type,tmaim_is_valid,tmaim_code,tmaim_time,create_by,create_time,last_modify_by,last_modify_time) values(");
			buff.append("'").append(tmaim_id).append("'")
			.append(",'").append("1").append("'")
			.append(",'").append("0").append("'")
			.append(",'").append("1").append("'")
			.append(",'").append(tmaim_code).append("'")
			.append(",'").append(create_time).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("'")
			.append(",'").append(create_by).append("'")
			.append(",'").append(create_time).append("')");
			list.add(buff.toString());
			buff.setLength(0);
			array = JSONArray.fromObject(ids);
			for(int i=0;i<array.size();i++){
				jsonObject = array.getJSONObject(i);
				buff.append("insert into TMA_INCOME_DETAIL(tmaid_id,tmaim_id,tmad_id,tmaid_num,create_by,create_time,last_modify_by,last_modify_time) values(")
				.append("'").append(AccessDataBaseUtil.getPKUUID()).append("'")
				.append(",'").append(tmaim_id).append("'")
				.append(",'").append(jsonObject.getString("tmad_id")).append("'")
				.append(",'").append(jsonObject.getString("tmaid_num")).append("'")
				.append(",'").append(create_by).append("'")
				.append(",'").append(create_time).append("'")
				.append(",'").append(create_by).append("'")
				.append(",'").append(create_time).append("')");
				list.add(buff.toString());
				buff.setLength(0);
			}
		}
		AccessDataBaseUtil.executeSQLUpdate(list);
		return "\"修改成功\"";
	}
	
	/** 
	 * 描述：select 查询入库计划记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	@Override
	public Object select(Object jsonArray) throws Exception {
		UserBean user = (UserBean)(this.getRequest()).getSession().getAttribute("userBean");
		String org_id = user.getCurOrgId();
		StringBuffer buff = new StringBuffer(" from tma_income_plan_main a,t_department b,t_user c where a.org_id=b.department_id and a.create_by=c.user_id");
		buff.append(" and a.org_id='").append(org_id).append("'");
		String countSql = "select count(*)" + buff.toString();
		String querySql = "select a.tmaipm_id,a.tmaipm_code,a.tmaipm_year,a.tmaipm_time,a.org_id,b.caption,c.caption as create_by,a.tmaipm_is_valid" + buff.toString();
		String[] fields = {"tmaipm_id","tmaipm_code","tmaipm_year","tmaipm_time","org_id","caption","create_by","tmaipm_is_valid"};
		return AccessDataBaseUtil.query4SQLPagging(fields, countSql, querySql, this.getPage(), this.getPagesize(), null);
	}
	
	/** 
	 * 描述：yao 查询药记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	public Object yao(Object jsonArray) throws Exception {
		UserBean user = (UserBean)(this.getRequest()).getSession().getAttribute("userBean");
		String org_id = user.getCurOrgId();
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		String year = jsonObject.getString("year");
		int nian = Integer.valueOf(year);
		List<Object> param = AccessDataBaseUtil.query4List("select sc_value from t_system_config where SC_KEY = 'yearPlanDate' and sc_marked", null);
		StringBuffer buff = new StringBuffer();
		if(param == null || param.size() == 0){
			buff.append(" from tma_dictionary a inner join tm_general_dictionary b on a.tmad_kind=b.tmgd_id and a.tmad_status='0' and b.tmgd_type='105'");
			buff.append(" left join (select d.tmad_id,c.org_id,c.tmaam_time,d.tmaad_num,e.caption from tma_apply_main c,tma_apply_detail d,t_department e where c.tmaam_id=d.tmaam_id and c.org_id=e.department_id and c.tmaam_status in ('0','3') and c.org_id in (select f.department_id from t_department f where f.dparent_id='").append(org_id).append("') and c.tmaam_time like '%").append(nian - 1).append("%' group by d.tmad_id,c.org_id,c.tmaam_time,e.caption) cde")
			.append(" on a.tmad_id=cde.tmad_id group by a.tmad_id ");
		}else{
			String min = nian - 1 + "-" + param.get(0);
			String max = nian + "-" + param.get(0);
			buff.append(" from tma_dictionary a inner join tm_general_dictionary b on a.tmad_kind=b.tmgd_id and a.tmad_status='0' and b.tmgd_type='105'");
			buff.append(" left join (select d.tmad_id,c.org_id,c.tmaam_time,d.tmaad_num,e.caption from tma_apply_main c,tma_apply_detail d,t_department e where c.tmaam_id=d.tmaam_id and c.org_id=e.department_id and c.tmaam_status in ('0','3') and c.org_id in (select f.department_id from t_department f where f.dparent_id='").append(org_id).append("') and c.tmaam_time >= '").append(min).append("' and c.tmaam_time < '").append(max).append("' group by d.tmad_id,c.org_id,c.tmaam_time,e.caption) cde")
			.append(" on a.tmad_id=cde.tmad_id group by a.tmad_id ");
		}
		String sortname = this.getRequest().getParameter("sortname");
		String sortorder = this.getRequest().getParameter("sortorder");
		if(sortname != null && sortname != null) {
			buff.append(" order by ").append(sortname).append(" ").append(sortorder).append(",a.tmad_kind desc,a.tmad_name");
		}else{
			buff.append(" order by a.tmad_kind desc,a.tmad_name");
		}
		String querySql = "select a.tmad_id,cde.org_id,cde.caption,b.tmgd_name,a.tmad_name,a.tmad_spec,a.tmad_unit,a.tmad_install,a.tmad_price,sum(case when cde.tmaad_num is null then 0 else cde.tmaad_num end) as tmaad_num,0 as shuliang,a.tmad_qgp,a.tmad_memo" + buff.toString();
		String[] fields = {"tmad_id","org_id","caption","tmgd_name","tmad_name","tmad_spec","tmad_unit","tmad_install","tmad_price","tmaad_num","shuliang","tmad_qgp","tmad_memo"};
		List<Map<String, String>> list = AccessDataBaseUtil.query(fields, querySql, null);
		array = JSONArray.fromObject(list);
		return "{\"Rows\":" + array.toString() + "}";
	}
	
	/** 
	 * 描述：modyao 查询药记录
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Jul 10, 2012  5:12:42 PM
	 * @author liu_zhaojun
	 */
	public Object modYao(Object jsonArray) throws Exception {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		String tmaipm_id = jsonObject.getString("tmaipm_id");
		StringBuffer buff = new StringBuffer(" from tma_dictionary a inner join tm_general_dictionary b on a.tmad_kind=b.tmgd_id and a.tmad_status='0' and b.tmgd_type='105'"); 
		buff.append(" left join (select d.tmaipd_id,d.tmad_id,c.org_id,e.caption,d.tmaipm_packages_num,d.tmaipm_num from tma_income_plan_main c,tma_income_plan_detail d,t_department e where c.org_id=e.department_id and c.tmaipm_id=d.tmaipm_id and d.tmaipm_id='").append(tmaipm_id).append("') cd")
		.append(" on a.tmad_id=cd.tmad_id ");
		String sortname = this.getRequest().getParameter("sortname");
		String sortorder = this.getRequest().getParameter("sortorder");
		if(sortname != null && sortname != null) {
			buff.append(" order by ").append(sortname).append(" ").append(sortorder).append(",a.tmad_kind desc,a.tmad_name");
		}else{
			buff.append(" order by a.tmad_kind desc,a.tmad_name");
		}
		String querySql = "select cd.tmaipd_id,a.tmad_id,cd.org_id,cd.caption,b.tmgd_name,a.tmad_name,a.tmad_spec,a.tmad_unit,a.tmad_install,a.tmad_price,(case when cd.tmaipm_num is null then 0 else cd.tmaipm_num end) as tmaad_num,cd.tmaipm_packages_num as shuliang,a.tmad_qgp,a.tmad_memo" + buff.toString();
		String[] fields = {"tmaipd_id","tmad_id","org_id","caption","tmgd_name","tmad_name","tmad_spec","tmad_unit","tmad_install","tmad_price","tmaad_num","shuliang","tmad_qgp","tmad_memo"};
		List<Map<String, String>> list = AccessDataBaseUtil.query(fields, querySql, null);
		array = JSONArray.fromObject(list);
		return "{\"Rows\":" + array.toString() + "}";
	}
	
	/** 
	 * 描述：expData 导出
	 * @param jsonArray
	 * @return
	 * @throws Exception
	 * @CreateOn Sep 5, 2012  5:06:00 PM
	 * @author liu_zhaojun
	 */
	public Object expData(Object jsonArray) throws Exception {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		String tmaipm_id = jsonObject.getString("tmaipm_id");
		UserBean user = (UserBean)(this.getRequest()).getSession().getAttribute("userBean");
		String org_id = user.getCurOrgId();
		StringBuffer buff = new StringBuffer("select b.tmgd_name,a.tmad_name,a.tmad_spec,a.tmad_unit,a.tmad_install,a.tmad_price,cd.tmaipm_num,cd.tmaipm_num*a.tmad_price,cd.tmaipm_packages_num,a.tmad_qgp,a.tmad_memo");
		buff.append(" from tma_dictionary a left join tm_general_dictionary b on a.tmad_kind=b.tmgd_id and a.tmad_status='0' and b.tmgd_type='105'")
		.append(" inner join (select d.tmad_id,d.tmaipm_packages_num,d.tmaipm_num from tma_income_plan_main c,tma_income_plan_detail d where c.tmaipm_id=d.tmaipm_id and d.tmaipm_id='").append(tmaipm_id).append("' and org_id='").append(org_id).append("') cd on a.tmad_id=cd.tmad_id order by a.tmad_kind desc,a.tmad_name");		
		List<Object[]> list = AccessDataBaseUtil.query(buff.toString(), null);	
		DecimalFormat format = new DecimalFormat("0.00");		
		String url = this.getRequest().getSession().getServletContext().getRealPath("/jsp/app/xls/");
		String model = url + "/model/tmaYearManager.xls";
		String file = url + "/file/tmaYearManager.xls";
		String rfile = "jsp/app/xls/file/tmaYearManager.xls";
		File ffrom = new File(model);
		File fto = new File(file);
		Common.copyFile(ffrom, fto);
		List<String> strList = new ArrayList<String>();
		strList.add("[{'num':'0','value':'制表：'},{'num':'7','value':'制表日期：'}]");
		strList.add("[{'num':'0','value':'负责人(签字)：'},{'num':'7','value':'负责人(签字)：'}]");
		strList.add("[{'num':'0','value':'人口计生委(盖章):'},{'num':'7','value':'药具管理站(盖章)：'}]");
		strList.add("[{'num':'0','value':'审批日期：'},{'num':'7','value':'编报日期：'}]");
		if(list.size() > 0){
			List<Object[]> l = new ArrayList<Object[]>();
			for(int i=0;i<list.size();i++){
				Object[] obj = list.get(i);
				String money = format.format(Double.valueOf(obj[7].toString()));
				obj[7] = money;
				l.add(obj);
			}		
			writeXls(l, fto, "年度计划申领", 3,strList);//写xls内容
		} else {
			return "{\"result\":false,\"resultmessage\":\"\",\"resultrecord\":\"导出结果集没有记录\"}";
		}
		
		return "\"" + rfile + "\"";
	}
	/** 
	 * 描述：writeXls 写XLS文件内容
	 * @param list 数据集
	 * @param file 写入文件
	 * @param title sheet页标题
	 * @param startRow xls数据起始行
	 * @throws Exception
	 * @CreateOn Sep 7, 2012  9:25:24 AM
	 * @author liu_zhaojun
	 */
	public static void writeXls(List<Object[]> list, File file, String title, int startRow,List<String> strList) throws Exception {
		POIFSFileSystem filein = new POIFSFileSystem(new FileInputStream(file));
		HSSFWorkbook book = new HSSFWorkbook(filein);
		HSSFSheet sheet = book.getSheet(title);
		int index = 0;
		double price = 0.00;
		double num = 0.00;
		double sum = 0.00;
		if(null != list && list.size() > 0){
			index = list.size();
			HSSFRow row = null;
			for (int i = 0; i < list.size(); i++) {// 行
				row = sheet.createRow(i + startRow);
				row.setHeight((short) 400);
				
				//序号
				HSSFCell cell = row.createCell(0);
				cell.setCellValue((i+1) + "");
				
				Object[] metaData = list.get(i);
				for(int j = 0; j < metaData.length; j++) {
					cell = row.createCell(j + 1);
					// 如果不是图片数据，就利用正则表达式判断textValue是否全部由数字组成
					String textValue = metaData[j].toString();
					cell.setCellValue(new HSSFRichTextString(textValue));
					if(j==5){
						price = Double.valueOf(textValue);
					}
					if(j==6){
						num = Double.valueOf(textValue);
					}
				}
				sum = sum + price * num;
			}
		}
		index = index + startRow;
		if(null != strList && strList.size() > 0){
			HSSFRow row = null;
			HSSFCell cell = null;
			row = sheet.createRow(index);
			row.setHeight((short) 400);
			cell = row.createCell(6);
			// 如果不是图片数据，就利用正则表达式判断textValue是否全部由数字组成
			cell.setCellValue(new HSSFRichTextString("总金额："));
			cell = row.createCell(7);
			// 如果不是图片数据，就利用正则表达式判断textValue是否全部由数字组成
			cell.setCellValue(new HSSFRichTextString(sum+""));
			for (int i = 0; i < strList.size(); i++) {// 行
				row = sheet.createRow(i + index + 1);
				row.setHeight((short) 400);
				JSONArray array = JSONArray.fromObject(strList.get(i));
				for(int j=0;j<array.size();j++){
					JSONObject jsonObject = array.getJSONObject(j);
					cell = row.createCell(Integer.valueOf(jsonObject.getString("num")));					
					// 如果不是图片数据，就利用正则表达式判断textValue是否全部由数字组成
					cell.setCellValue(new HSSFRichTextString(jsonObject.getString("value")));
				}			
			}
		}		
		FileOutputStream fileOut = new FileOutputStream(file);
		book.write(fileOut);
		fileOut.close();
	}

	@Override
	public Object run() {
		Object msg = "";
		try {
			if ("queryPage".equals(this.getMethodName())) {// 列表
				msg = this.select(this.getLogicData());
			} else if ("save".equals(this.getMethodName())) {// 添加
				msg = this.insert(this.getLogicData());
			} else if ("delete".equals(this.getMethodName())) {// 删除
				msg = this.delete(this.getLogicData());
			} else if ("yao".equals(this.getMethodName())) {
				msg = this.yao(this.getLogicData());
			} else if ("modYao".equals(this.getMethodName())) {
				msg = this.modYao(this.getLogicData());
			} else if ("update".equals(this.getMethodName())) {// 修改
				msg = this.update(this.getLogicData());
			} else if ("expData".equals(this.getMethodName())) {// 导出
				msg = this.expData(this.getLogicData());
			} else {
				msg = "\"没有【" + this.getMethodName() + "】该方法\"";
			}
			if(msg == null || "[null]".equals(msg)){
				msg = "\"\"";
			}
			if(msg.toString().startsWith("{") || msg.toString().startsWith("[")){
				return msg;
			}
			msg = ConstantInfoHelper.generateJSONString(msg.toString());
			//log.info(this.getClass().getName() +":"+this.getMethodName() + " -> " + msg);
		} catch (Exception e) {
			msg = "操作失败，请联系管理员";
			msg = ConstantInfoHelper.generateJSONString(ConstantInfoHelper.JSON_HEAD, ConstantInfoHelper.getFailResultDetail(msg.toString()), false);
			log.error(e, e);
		} finally {
			this.clear();
		}
		return msg.toString();
	}

	@Override
	public Object setRequest(HttpServletRequest request) throws Exception {
		this.request = request;
		return request;
	}

	@Override
	public Object updateBatch(Object jsonArray) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Object recordCount(Object jsonArray) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object onCreate(Object jsonArray) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object onDestory(Object jsonArray) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object onInit(Object jsonArray) {
		// TODO Auto-generated method stub
		return null;
	}

}
